﻿<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path;
%>
<!DOCTYPE HTML>
<html>
<head>
    <title>试题管理</title>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <script type="text/javascript" src="<%=basePath%>/assets/js/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/assets/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/assets/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/assets/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/assets/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>/assets/static/h-ui.admin/css/style.css"/>
    <script type="text/javascript" src="<%=basePath%>/assets/js/exam/examination-manage.js"></script>
    <script type="text/javascript" src="<%=basePath%>/assets/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>/assets/lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="<%=basePath%>/assets/static/h-ui/js/H-ui.min.js"></script>
    <style type="text/css">
        .stem {
            text-align: left;
            box-sizing: border-box;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            width: 400px;
            text-decoration: underline;
        }
    </style>
</head>
<body>
<nav class="breadcrumb" style="padding: 0 10px">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
    题库管理 <span class="c-gray en">&gt;</span> 试题管理 <a
        class="btn btn-success radius r"
        style="line-height: 1.6em; margin-top: 3px"
        href="javascript:location.replace(location.href);" title="刷新"><i
        class="Hui-iconfont">&#xe68f;</i> </a>
</nav>
<div class="page-container" style="padding: 6px;">
    <form method="post" id="searchInfoForm">
        <div class="text-c">
            <!--审核状态选择-->
            <select name="checkStatus" class="select select-box inline" id="checkStatus">
                <option value="">全部</option>
                <option value="未审核">未审核</option>
                <option value="一审未过">一审未过</option>
                <option value="一审通过">一审通过</option>
                <option value="二审未过">二审未过</option>
                <option value="二审通过">二审通过</option>
            </select>
            <select name="cognitiveLevel" class="select select-box inline" id="cognitiveLevel">
                <option >认知层次</option>
                <option >记忆</option>
                <option >理解</option>
                <option >应用</option>
            </select>

            <span class="  inline" style="border: 0;">
			 	<select name="pattern" id="area" onmouseout="selectChange()" class="select select-box inline"></select>
				<select name="first" id="cmbProvince" onmouseout="selectChange()"
                        class="select select-box inline"></select>
				<select name="second" id="cmbCity" onmouseout="selectChange()"
                        class="select select-box inline"></select>
				<select name="third" id="cmbArea" class="select select-box inline"></select>
			 </span>

            <input type="text" name="keywords" placeholder=" 请输入试题题干关键字......" style="width: 200px"
                   class="input-text">
            <button id="searchExaminations" class="btn btn-success" type="button">
                <i class="Hui-iconfont">&#xe665;</i> 筛选试题
            </button>
            <span class="inline"><a href="javascript:;" onclick="examination_batch_check()" class="btn btn-warning "><i
                    class="Hui-iconfont">&#xe725;</i> 批量审核</a> </span>
            <span class="inline"><a href="javascript:;" onclick="examination_batch_del()" class="btn btn-danger "><i
                    class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> </span>
        </div>
    </form>


    <div class="mt-20" style="text-align: center">
        <table
                class="table table-border table-bordered table-bg table-hover table-sort "
                id="examTable">
            <thead class="text-c">
            <tr>
                <th width="10px"><input type="checkbox"></th>
                <th >题干</th>
                <th width="70px">分类</th>
                <th width="30px">总分</th>
                <th width="60px">大纲代码</th>
                <th width="130px">知识点</th>
                <th width="50px">认知层次</th>
                <th width="130px">更新时间</th>
                <th width="50px">审核状态</th>
                <th width="60px">操作</th>
            </tr>
            </thead>
            <tbody class="text-c "></tbody>
        </table>
    </div>
</div>
<script type="text/javascript"
        src="<%=basePath%>/assets/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript"
        src="<%=basePath%>/assets/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
    var examTable;
    $(function () {
        examTable = $('#examTable').DataTable({
            "ajax": {
                url: "<%=basePath%>/examination/examinationList",
                type: "post",
                cache: false,
                data: function (d) {
                    var checkStatus = d.checkStatus = $('#checkStatus option:selected ').val();
                    var cognitiveLevel = d.cognitiveLevel = $('#cognitiveLevel option:selected ').val();
                    var pattern = d.pattern = $('#area option:selected').val();
                    var first = d.first = $('#cmbProvince option:selected').val();
                    var second = d.second = $('#cmbCity option:selected').val();
                    var third = d.third = $('#cmbArea option:selected').val();
                    var keywords = d.keywords = $('input[name="keywords"]').val();
                }
            },
            "serverSide": true,//打开后台分页
            "bSort": true,
            "aaSorting": [[1, "DESC"]], //默认第几个排序
            "bStateSave": true, //状态保存
            "bLengthChange": false,
            "bFilter": false,
            "iDisplayLength": 10,
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                {
                    "orderable": false,
                    "aTargets": [0]
                } // 不参与排序的列
            ],
            "bScrollCollapse": true, //高度自适应
            "columns": [{
                "render": function (data, type, row, meta) {
                    var id = row.id;
                    var category = row.category;
                    var checkStatus = row.checkStatus;
                    var examinationIdAndCategoryAndCheckStatusList = id + ";" + category + ";" + checkStatus;
                    return "<input type='checkbox' name='examinationIdAndCategoryAndCheckStatusList' value='" + examinationIdAndCategoryAndCheckStatusList + "'>";
                }
            },
                {
                    "data": "stem",
                    "render": function (data, type, row, meta) {
                        var id = row.id;
                        var category = row.category;
                        return "<u style='cursor:pointer' class='text-primary' onClick='examination_details(\"试题详情\",\"<%=basePath%>/examination/examinationDetails/" + id + "/" + category + "\")' title='查看试题详情'><div class='stem'>" + data + "</div></u>";

                    }
                }, {
                    "render": function (data, type, row, meta) {
                        var category = row.category;
                        var categoryName = getCategoryName(category);
                        return "<span >" + categoryName + "</span>";
                    },
                }, {
                    "data": "totalScore",
                }, {
                    "data": "outlineCode",
                }, {
                    "data": "knowledgePoint",
                }, {
                    "data": "cognitiveLevel",
                }, {
                    "data": "updatetime",
                }, {
                    "render": function (data, type, row, meta) {
                        var checkStatus = row.checkStatus;
                        if (checkStatus == '未审核' || checkStatus == '一审未过' || checkStatus == '二审未过') {
                            return "<span class='label label-danger radius'>" + checkStatus + "</span>";
                        }
                        return "<span class='label label-success radius'>" + checkStatus + "</span>";
                    },
                }, {
                    "render": function (data, type, row, meta) {
                        var id = row.id;
                        var checkStatus = row.checkStatus;
                        var category = row.category;
                        var examinationIdAndCategoryList = id + ";" + category;
                        /**
                         *@Author: 陈玉林
                         *@Date: 2017/8/24 10:25
                         *@Description: 一共有审核，修改，删除，撤销审核四种操作
                         * 一旦经过审核的试题就不能进行删除操作,也就是说只有在未审核状态下才可进行删除操作
                         * 未审核状态下没有撤销审核操作
                         */
                        if (checkStatus == "未审核") {
                            return "<span style=\"cursor: pointer;\"  class='text-c' onClick=\"examination_check('" + id + "','" + category + "','" + checkStatus + "') \">审核</span><a style='text-decoration:none' class='ml-5' onClick='exam_update(\"" + id + "\",\"" + category + "\",\"<%=basePath%>/examination/intoExaminationUpdate\")'  href='javascript:;'  title='修改'><i class='Hui-iconfont'>&#xe6df;</i></a><a style='text-decoration:none' class='ml-5'onClick=\"exam_del(this,'" + examinationIdAndCategoryList + "')\"  href='javascript:;'title='删除'><i class='Hui-iconfont'>&#xe6e2;</i> </a>";
                        }
                        if (checkStatus == "一审通过") {
                            return "<span style=\"cursor: pointer;\"  class='text-c' onClick=\"examination_check('" + id + "','" + category + "','" + checkStatus + "') \">审核</span><a style='text-decoration:none' class='ml-5' onClick='exam_update(\"" + id + "\",\"" + category + "\",\"<%=basePath%>/examination/intoExaminationUpdate\")'  href='javascript:;'  title='修改'><i class='Hui-iconfont'>&#xe6df;</i></a><a style='text-decoration:none' class='ml-5' onClick=\"exam_cancel_check('" + id + "','" + category + "','" + checkStatus + "')\"  href='javascript:;'  title='撤销审核'><i class='Hui-iconfont'>&#xe66b;</i></a>";
                        }
                        if (checkStatus == "二审通过") {
                            return "<span style=\"cursor: pointer;\"  class='text-c' onClick=\"examination_check('" + id + "','" + category + "','" + checkStatus + "') \">审核</span><a style='text-decoration:none' class='ml-5' onClick='exam_update(\"" + id + "\",\"" + category + "\",\"<%=basePath%>/examination/intoExaminationUpdate\")'  href='javascript:;'  title='修改'><i class='Hui-iconfont'>&#xe6df;</i></a><a style='text-decoration:none' class='ml-5' onClick=\"exam_cancel_check('" + id + "','" + category + "','" + checkStatus + "')\"  href='javascript:;'  title='撤销审核'><i class='Hui-iconfont'>&#xe66b;</i></a>";
                        }
                        return "<span style=\"cursor: pointer;\"  class='text-c' onClick=\"examination_check('" + id + "','" + category + "','" + checkStatus + "') \">审核</span><a style='text-decoration:none' class='ml-5' onClick='exam_update(\"" + id + "\",\"" + category + "\",\"<%=basePath%>/examination/intoExaminationUpdate\")'  href='javascript:;'  title='修改'><i class='Hui-iconfont'>&#xe6df;</i></a><a style='text-decoration:none' class='ml-5' onClick=\"exam_cancel_check('\" + id + \"','\" + category + \"','\" + checkStatus + \"')\"  href='javascript:;'  title='撤销审核'><i class='Hui-iconfont'>&#xe66b;</i></a>";
                    }
                }],
        });
    });
    //试题搜索
    $("#searchExaminations").click(function () {
        examTable.ajax.reload();
    });

    /* 查看试题详情 */
    function examination_details(title, url, id, w, h) {
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }

    /**
     *@Author: 陈玉林
     *@Date: 2017/8/11 15:02
     *@Description: 试题修改
     */
    function exam_update(id, category, url) {
        $.ajax({
            url: "<%=basePath%>/examination/volidateAuthorizationForExamUpdate",
            type: "post",
            dataType: "json",
            data: {id: id},
            success: function (data) {
                if (data.code != null && data.code == 200) {
                    layer.msg(data.msg, {icon: 5, time: 2000});
                } else if (data.code == 300) {
                    layer.alert(data.msg);
                    examTable.ajax.reload();
                }
                else {
                    layer.open({
                        type: 2,
                        title: '试题修改',
                        shadeClose: false, //点击遮罩关闭
                        shade: 0.8,
                        area: ['100%', '100%'],
                        maxmin: true,
                        closeBtn: 1,
                        content: "<%=basePath%>/examination/intoExaminationUpdate/" + id + "/" + category, //iframe的url，yes是否有滚动条
                    });
                }
            }
        });
    }


    /**
     *@Author: 陈玉林
     *@Date: 2017/8/11 15:02
     *@Description: 试题审核
     * 二审通过后不能进行通过或者不通过审核，但是可以进行撤销审核
     */
    function examination_check(id, category, checkStatus) {
        layer.confirm('是否通过审核？', {icon: 3, btn: ['通过', '不通过']}, function (index) {                 //这里的icon:3 是‘？’图标，在上次博客试出来的共存方法
            layer.close(index);
            if (checkStatus == '二审通过') {
                layer.msg('该试题已经审核完毕！', {
                    icon: 4,
                    time: 2000
                });
                return false;
            }
            $.ajax({
                type: 'GET',
                url: "<%=basePath%>/examination/examinationCheck",
                data: {id: id, category: category, checkStatus: checkStatus},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    } else if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();//试题审核完成后重新加载table
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        })
        $('.layui-layer-btn1').click(function () {                           //  .layui-layer-btn1 = 右边按钮class名
            if (checkStatus == '二审通过') {
                layer.msg('改试题已经审核完毕！', {
                    icon: 4,
                    time: 2000
                });
                return false;
            }
            layer.prompt({title: '请输入备注信息', formType: 2}, function (text, index) {
                layer.close(index);
                $.ajax({
                    url: "<%=basePath%>/examination/examinationCheck",
                    type: "post",
                    dataType: "json",
                    data: {id: id, category: category, checkStatus: checkStatus, mark: text},
                    success: function (data) {
                        if (data.code == 200) {
                            layer.msg(data.msg, {
                                icon: 5,
                                time: 2000
                            });
                        } else if (data.code == 0) {
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            });
                            examTable.ajax.reload();//试题审核完成后重新加载table
                        } else {
                            layer.msg(data.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    }
                });
            });
        })
    }

    /**
     *@Author: 陈玉林
     *@Date: 2017/8/24 9:16
     *@Description: 撤销审核
     */
    function exam_cancel_check(id, category, checkStatus) {
        layer.confirm('确认要撤销审核吗？', function (index) {
            $.ajax({
                data: {id: id, category: category, checkStatus: checkStatus, cancelCheck: 'true'},
                type: 'GET',
                url: '<%=basePath%>/examination/examinationCheck',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    } else if (data.code == 300) {
                        layer.alert(data.msg);
                        examTable.ajax.reload();//试题审核完成后重新加载table
                    } else if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();//试题审核完成后重新加载table
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }


    /* 试题批量审核 */
    function examination_batch_check() {
        var original = [];
        var later = [];
        $("input:checkbox[name='examinationIdAndCategoryAndCheckStatusList']:checked").each(function () {
            original.push($(this).val());
        });
        var originalLen = original.length;//数组原始长度
        for (var i = 0; i < original.length; i++) {
            var arr = original[i].split(";");//切分 arr[0]为试题id;arr[1]为试题分类;arr[2]为试题审核状态;若是arr[2]=='二审通过，则不必添加，过滤掉'
            if (arr[2] != '' && arr[2] != '二审通过') {
                later.push(original[i] + ";" + 'check');//拼接一个check标识，便于区分批量删除
            }
        }
        var laterLen = later.length;//数组过滤后长度
        if (originalLen == 0) {
            layer.msg('请选择试题!', {icon: 3, time: 2000});
            return;
        }
        if (originalLen != 0 && laterLen == 0) {
            layer.msg('所选试题已经审核完毕!', {icon: 4, time: 2000});
            return;
        }
        var msc;
        msc = '确定通过所选试题？';
        if (laterLen < originalLen) {
            msc = '所选试题包含审核完毕试题，将被系统忽略,确定通过所选试题？';
        }
        console.log(later);
        layer.confirm(msc, function (index) {
            $.ajax({
                type: "post",
                url: "<%=basePath%>/examination/examinationBatchCheck",
                data:{"examinationIdAndCategoryList" : later},
                dataType: "json",
                traditional: true,
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                    setTimeout(function () {
                        examTable.ajax.reload();
                    }, 1000);
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }




    /*试题-删除*/
    function exam_del(obj, examinationIdAndCategoryList) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                data: {examinationIdAndCategoryList: examinationIdAndCategoryList},
                type: 'GET',
                url: '<%=basePath%>/examination/examinationDelete',
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    } else if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }
                    examTable.ajax.reload();
                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }


    //试题批量删除
    function examination_batch_del() {
        var original = [];
        var later = [];
        $("input:checkbox[name='examinationIdAndCategoryAndCheckStatusList']:checked").each(function () {
            original.push($(this).val());
        });
        var originalLen = original.length;//数组原始长度
        for (var i = 0; i < original.length; i++) {
            var arr = original[i].split(";");//切分 arr[1]代表分类 arr[2]代表审核状态
            if (arr[2] != '' && arr[2] == '未审核') {//只有未审核的试题才让删除
                later.push(original[i]);
            }
        }
        var laterLen = later.length;//数组过滤后长度
        if (originalLen == 0) {
            layer.msg('请选择试题!', {icon: 3, time: 2000});
            return;
        }
        if (originalLen != 0 && laterLen == 0) {
            layer.msg('所选试题已经进行过审核,不能删除!', {icon: 4, time: 2000});
            return;
        }
        var msc;
        msc = '确定删除所选试题？';
        if (laterLen < originalLen) {
            msc = '所选试题包含已审核试题，将不会被系统删除,确定删除所选试题？';
        }
        layer.confirm(msc, function (index) {
            $.ajax({
                type: "post",
                url: "<%=basePath%>/examination/examinationBatchDelete",
                data:{"examinationIdAndCategoryList" : later},
                dataType: "json",
                traditional: true,
                success: function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, {
                            icon: 5,
                            time: 2000
                        });
                    } else if (data.code == 0) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        });
                        examTable.ajax.reload();//试题审核完成后重新加载table
                    } else {
                        layer.msg(data.msg, {
                            icon: 2,
                            time: 2000
                        });
                    }

                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }

    //试题分类初始化
    addressInit('area', 'cmbProvince', 'cmbCity', 'cmbArea', '西北地区', '北京', '市辖区', '东城区');

    function getCategoryName(category) {
        switch (category) {
            case '1':
                category = "内科按摩学";
                break;
            case '2':
                category = "妇科按摩学";
                break;
            case '3':
                category = "儿科推拿学";
                break;
            case '4':
                category = "伤科按摩学";
                break;
            case '5':
                category = "成人穴位";
                break;
            case '6':
                category = "儿科穴位";
                break;
            case '7':
                category = "成人手法";
                break;
            case '8':
                category = "儿科手法";
                break;
            case '9':
                category = "伤科";
                break;
            case '10':
                category = "妇科";
                break;
            case '11':
                category = "儿科";
                break;
            case '12':
                category = "内科";
                break;
            case '13':
                category = "腧穴试题";
                break;
            case '14':
                category = "客观化穴位";
                break;
            case '15':
                category = "客观化单项";
                break;
            default:
                break;
        }
        return category;
    };
</script>
</body>

</html>